<template>
    <div class="app-container qianyue">
        <el-table v-loading="loading" :data="userinfoList" v-show="openShow">
            <el-table-column type="selection" width="55" align="center" />
            <el-table-column label="编号" align="center" prop="uid" />
            <el-table-column
                label="企业名称"
                align="center"
                prop="company_name"
            />
            <el-table-column
                label="开始时间"
                align="center"
                prop="start_time"
            />
            <el-table-column label="结束时间" align="center" prop="end_time" />
            <!--<el-table-column label="结算方式" align="center" prop="" />-->
            <el-table-column label="是否授信" align="center" prop="set_type" />
            <el-table-column
                label="合同附件"
                align="center"
                class-name="small-padding fixed-width"
            >
                <template slot-scope="scope">
                    <el-button
                        size="mini"
                        type="text"
                        icon="el-icon-download"
                        @click="localfile(scope.row.deal_file)"
                        >下载</el-button
                    >
                </template>
            </el-table-column>

            <el-table-column
                label="操作"
                align="center"
                class-name="small-padding fixed-width"
            >
                <template slot-scope="scope">
                    <el-button
                        size="mini"
                        type="text"
                        icon="el-icon-check"
                        @click="
                            submit(
                                scope.row.uid,
                                scope.row.signStatus,
                                scope.row
                            )
                        "
                    >
                        <!--0不显示  1已确认 2确认 -->
                        <!-- switch (key) {
                                    case value:

                                        break;

                                    default:
                                        break;
                                } -->
                        {{
                            scope.row.signStatus == 2
                                ? "确认"
                                : scope.row.signStatus == 1
                                ? "已确认"
                                : "未确认"
                        }}
                    </el-button>
                </template>
            </el-table-column>
        </el-table>
        <div v-show="!openShow" class="test">
            等待管理员发出签约邀请！
        </div>
    </div>
</template>

<script>
import {
    listUserinfo,
    getUserinfo,
    delUserinfo,
    addUserinfo,
    updateUserinfo,
    exportUserinfo
} from "@/api/biz/userinfo";
import { getToken } from "@/utils/auth";
export default {
    name: "qianyue",
    data() {
        return {
            // 遮罩层
            loading: true,
            // 选中数组
            ids: [],
            // 非单个禁用
            single: true,
            // 非多个禁用
            multiple: true,
            readonly: false,
            // 总条数
            total: 0,
            // 用户详情表格数据
            userinfoList: [],
            // 弹出层标题
            title: "",
            // 是否显示弹出层
            open: false,
            openShow: true
        };
    },
    created() {
        this.getUrl("/web/getCurrectUserinfo").then(response => {
            if (response.data.signStatus == "0") {
                this.openShow = false;
            }
        });
        this.getList();
    },
    methods: {
        localfile(url) {
            if (url) {
                // window.open(process.env.VUE_APP_BASE_API + url);
                if (window.navigator.msSaveBlob) {  // IE以及IE内核的浏览器
                    try {
                      window.navigator.msSaveBlob(res, fileName)  // res为接口返回数据，这里请求的时候已经处理了，如果没处理需要在此之前自行处理var data = new Blob([res.data]) 注意这里需要是数组形式的,fileName就是下载之后的文件名
                      // window.navigator.msSaveOrOpenBlob(res, fileName);  //此方法类似上面的方法，区别可自行百度
                    } catch (e) {
                      console.log(e)
                    }
                  } else {
                    let link = document.createElement('a')
                    link.href = process.env.VUE_APP_BASE_API + url 
                    // let url = window.URL.createObjectURL(new Blob([res]))
                    link.style.display = 'none'
                    document.body.appendChild(link)
                    link.click()
                    document.body.removeChild(link) // 下载完成移除元素
                    window.URL.revokeObjectURL(url) // 释放掉blob对象
                  }
            }
        },
        /** 查询用户详情列表 */
        getList() {
            this.loading = true;
            this.getUrl("/web/getCurrectUserinfo").then(response => {
                if (response.data.set_type == "1") {
                    response.data.set_type = "是";
                } else {
                    response.data.set_type = "否";
                }

                this.userinfoList = [response.data];

                this.total = 1;
                this.loading = false;
            });
        },
        submit(uid, status, row) {
            if (status == 1) {
                return;
            }
            this.getUrl("/web/confirm/" + uid).then(response => {
                if (response.code == 200) {
                    this.msgSuccess("操作成功");
                    // this.getList();
                    row.signStatus = 1;
                } else {
                    this.msgError("操作失败");
                }
            });
        }
    }
};
</script>
<style>
.qianyue .test {
    width: 100%;
    text-align: center;
    font-size: 24px;
    line-height: 24px;
    margin-top: 30vh;
}
</style>
